package sjms.construction.proxy.dynamic;

import java.lang.reflect.Proxy;

/**
 * @ClassName:
 * @Description:
 * @Author fcb
 * @Date 2020/6/5 12:46
 */
public class ProxyFactory {

    private Object target;

    public ProxyFactory(Object target){
        this.target = target;
    }

    // 方法中的第三个参数为InvocationHandler接口的实现类
    public Object getProxyInstance(){

        return Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                (t, method, args) ->{
                    System.out.println("代理执行");
                    Object result = method.invoke(target,args);
                    return result;
                });
    }
}
